package com.zhuchaooasystem.widget;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.zhuchaooasystem.R;


/**
 * @author yinsi
 */
public class ConfirmDialog extends AlertDialog {

    private TextView txt_title;
    private TextView txt_content;
    private Button btn_ok;
    private Button btn_cancle;
    //----
    private OnViewClickListener listenner;

    public ConfirmDialog(Context context) {
        super(context);
    }

    protected ConfirmDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public ConfirmDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try {
            setContentView(R.layout.dlg_confirm);
            //----
            txt_title = (TextView) findViewById(R.id.dialog_confirm_tv_title);
            txt_content = (TextView) findViewById(R.id.dialog_confirm_tv_content);
            btn_ok = (Button) findViewById(R.id.dialog_confirm_tv_ok);
            btn_cancle = (Button) findViewById(R.id.dialog_confirm_tv_cancel);
            btn_ok.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listenner != null) {
                        listenner.onClickOk(ConfirmDialog.this);
                    } else {
                        dismiss();
                    }
                }
            });
            btn_cancle.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listenner != null) {
                        listenner.onClickCancel(ConfirmDialog.this);
                    } else {
                        dismiss();
                    }
                }
            });
        } catch (Exception e) {
        }
    }

    public void setTextTitle(String title) {
        if (null != txt_title) {
            txt_title.setText(title);
        }
    }

    public void setTextContent(String content) {
        if (null != txt_content) {
            txt_content.setText(content);
        }
    }

    public interface OnViewClickListener {
        void onClickOk(ConfirmDialog dialog);

        void onClickCancel(ConfirmDialog dialog);
    }

    public void setOnViewClickListener(OnViewClickListener listener) {
        this.listenner = listener;
    }

}
